<?php

if (!function_exists('encrypt')) {
    /**
     * Author:Yingbo Sun
     * 加密算法
     * @param $id
     * @return false|string
     */
    function encrypt($id)
    {
        //加盐
        $salt = '&*&*';
        $method = 'AES-128-ECB';
        $data = config('setting.saltRand').openssl_encrypt($id, $method, $salt,0);
        return openssl_encrypt($data, $method, $salt,0);
    }
}

if (!function_exists('decrypt')) {
    /**
     * Author:Yingbo Sun
     * 解密算法
     * @param $data
     * @return false|string
     */
    function decrypt($data)
    {
        //加盐
        $salt = '&*&*';
        $method = 'AES-128-ECB';
        $data = openssl_decrypt($data, $method, $salt,0);
        $data = str_replace(config('setting.saltRand'),'',$data);
        return openssl_decrypt($data, $method, $salt,0);
    }
}

if (!function_exists('produceCode')){
    /**
     * Author:Yingbo Sun
     * 生成六位随机数
     * @return int
     */
    function produceCode()
    {
        $code = mt_rand(100000,999999);
        return $code;
    }
}

if (!function_exists('verifyPhone')){
    /**
     * Author:Yingbo Sun
     * 手机号正则验证
     * @param $phone
     * @return bool
     */
    function verifyPhone($phone)
    {
        $g = "/^1[3456789]\d{9}$/";
        if (preg_match($g,$phone)){
            return true;
        }else{
            return false;
        }
    }
}

if (!function_exists('isInt')) {
    /**
     * Author:Zhongyuan Lu
     * 判断整型数据
     * @param $param
     * @return bool
     */
    function isInt($param)
    {
        if (!is_int($param) || $param <= 0) {
            return false;
        }
        return true;
    }
}


